<template>
	<view class="page" :style="{minHeight:$height()}">
		<view class="header">
			<view class="bannerBox">
				<video v-if="course && course.videoUrl" @play="play" :src="$utils.imagePath(course.videoUrl)" style="width: 100%; height: 100%;" maxDuration="100"></video>
			</view>
			<view class="tabBox">
				<view class="tab" style="margin-right: 126rpx;" @click="changeIdx(0)">
					<view class="word">
						课程介绍
					</view>
					<view class="bottomLine">

					</view>
				</view>
				<view class="tab"  @click="changeIdx(1)">
					<view class="word">
						课程附件
					</view>
					<view class="bottomLine">
					</view>
				</view>
			</view>
		</view>
		<view class="footer1" v-if="idx == 0">
			<view class="ail">
				{{course.title}}
			</view>
			<view class="infoBox">
				<!-- <u-icon name="phone"></u-icon> -->
				<image src="@/static/Icon/fang.png" mode="" style="width: 33rpx; height: 33rpx;"></image>
				<view class="course" style="margin: 0 20rpx;">
					一共{{course.videoLength}}课时
				</view>
				<view class="personNubmer">
					{{course.learnNum}}人已学
				</view>
			</view>
			<view class="line">

			</view>
			<view class="ail">
				课程简介
			</view>
			<view class="massge">
				<u-parse :html="course.describe" ></u-parse>
			</view>
		</view>

		<view class="footer2" v-if="idx == 1">
			<view class="infoText">
				文档类附件
			</view>
			<view class="list" v-for="(item,index) in course.courseAttachList" :key="index"  v-if="item.type == 0">
				<view class="liBox">
					<image src="@/static/Icon/fil.png" style="width: 16rpx; height: 20rpx;"></image>
					<view class="wen">
						{{item.title}}
					</view>
				</view>
				<image @click="downLoad(item.url)" src="@/static/Icon/dowload.png" style="width: 16rpx; height: 18rpx;"></image>
			</view>
			

			<view class="infoText">
				授课视频 / 音频
			</view>
			<view class="list" v-for="(item,index) in course.courseAttachList" :key="index"  v-if="item.type == 1">
				<view class="liBox">
					<image src="@/static/Icon/fil.png" style="width: 16rpx; height: 20rpx;"></image>
					<view class="wen">
						{{item.title}}
					</view>
				</view>
				<image @click="downLoad(item.url)" src="@/static/Icon/dowload.png" style="width: 16rpx; height: 18rpx;"></image>
			</view>
			

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				idx:0,
				id:0,
				course:{}
			}
		},
		onLoad(options) {
			this.id = options.id
		},
		onShow() {
			this.getCourse()
		},
		methods: {
			play(e){
				this.$axios.request(`${this.$api.doPlay}/${this.id}`).then((val) => {
					
				})
			},
			getCourse(){
				this.$axios.request(`${this.$api.getCourse}/${this.id}`,"GET").then((val) => {
					this.course = val.data
					uni.setNavigationBarTitle({
						title:val.data.title
					})
				})
			},
			downLoad(url){
				uni.downloadFile({
					url:this.$utils.imagePath(url),
					success: (temp) => {
						console.log(temp)
						if(temp.statusCode==200){
							//保存到本地
							uni.saveFile({
								tempFilePath:temp.tempFilePath,
								success:(res)=>{
									 //保存成功并打开文件
									 uni.openDocument({
										filePath:res.savedFilePath,
										success:(res)=>console.log('成功打开文档')
									})
								},
								fail:(e)=> {
									console.log(e)
								}
							})
						}
					},
					fail: (err) => {
						console.log(err)
					}
				})
				
			},
			changeIdx(idx){
				this.idx = idx
			},
			
		}
	}
</script>

<style>
	.page {
		width: 100%;
		/* background-color: #F3F4F8; */
		border-left: 2rpx solid #FFFFFF;
		overflow: hidden;
	}

	.header {
		width: 100%;
		height: 414rpx;
		background-color: #FFFFFF;
		margin: 16rpx 0 0;
	}

	.bannerBox {
		width: 100%;
		height: 318rpx;
	}

	.tabBox {
		display: flex;
		justify-content: center;
		align-items: flex-end;
		width: 702rpx;
		height: 95rpx;
		margin: 0 auto 0;
		border-bottom: 2rpx solid #E1E1E1;
	}

	.tab {
		display: flex;
		flex-direction: column;
		justify-content: flex-end;
		align-items: center;
		width: 112rpx;
		height: 56rpx;
		/* background-color: #2C405A; */
	}

	.word {
		width: 112rpx;
		font-size: 28rpx;
		font-family: "PingFang SC";
		font-weight: 600;
		color: #333333;
		text-align: center;
		opacity: 1;
	}

	.bottomLine {
		width: 82rpx;
		height: 6rpx;
		opacity: 1;
		border-radius: 3rpx;
		margin-top: 16rpx;
	}

	.footer1 {
		overflow: hidden;
		width: 100%;
		height: 100%;
		padding: 0 24rpx;
		background-color: #FFFFFF;
	}

	.ail {
		font-size: 28rpx;
		font-family: "PingFang SC";
		font-weight: 600;
		line-height: 46rpx;
		color: #333333;
		opacity: 1;
		margin: 34rpx auto 16rpx;
	}

	.infoBox {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		height: 33rpx;
	}

	.course,
	.personNubmer {
		font-size: 24rpx;
		font-family: "PingFang SC";
		font-weight: 400;
		color: #666666;
		opacity: 1;
	}

	.line {
		width: 702rpx;
		height: 10rpx;
		background: rgba(243, 244, 248, 0.39);
		opacity: 1;
		margin: 13rpx auto 0;
	}

	.massge {
		width: 100%;
		padding:10rpx;
		font-size: 24rpx;
		font-family: "PingFang SC";
		font-weight: 400;
		line-height: 46rpx;
		color: #666666;
		opacity: 1;
	}

	.footer2 {
		overflow: hidden;
		width: 100%;
		height: 100%;
		padding: 0 24rpx;
		background-color: #FFFFFF;
	}

	.infoText {
		font-size: 28rpx;
		font-family: "PingFang SC";
		font-weight: 600;
		line-height: 46rpx;
		color: #333333;
		opacity: 1;
		margin-top: 34rpx;
	}

	.list {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 622rpx;
		margin: 16rpx 0 0 24rpx;
	}

	.liBox {
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}

	.wen {
		margin-left: 16rpx;
		font-size: 24rpx;
		font-family: "PingFang SC";
		font-weight: 300;
		line-height: 11rpx;
		color: #666666;
		opacity: 1;
	}
	.tab:hover .bottomLine {
		background: rgba(46, 106, 223, 0.39);
	}
</style>
